#ifndef __UDSF_UDK_ADDR_GET__
#define __UDSF_UDK_ADDR_GET__

#include "app.h"

/*
*   notice:
*   UDSF 同UDF编程：不可调用cstd-lib,只可调用"sdk_ifs_udk_cfg.h"、"sys_api.h"中列出的API函数。
*   UDSF文件内函数均需使用static修饰符，且UDF中以#include "udsf_xxx.c"形式引用
*/

static uint32_t udsf_udk_addr_get_opt_data(uint8_t app_location) __attribute__((unused));
static uint32_t udsf_udk_addr_get_signature(void) __attribute__((unused));
static uint32_t udsf_udk_addr_get_activate(void) __attribute__((unused));

static uint32_t udsf_udk_addr_get_app_default(uint8_t app_location) __attribute__((unused));
static uint32_t udsf_udk_addr_get_app_default(uint8_t app_location){
	
	uint32_t addr_app_rsv = SYSBOOT_APP_BASE_OUTER;
	if( app_location == APP_LOCATION_INNER ){
		addr_app_rsv = SYSBOOT_APP_BASE_INNER;
	}
	return addr_app_rsv;
}

static uint32_t udsf_udk_addr_get_app_rsv(uint8_t app_location) __attribute__((unused));
static uint32_t udsf_udk_addr_get_app_rsv(uint8_t app_location){
	
	uint32_t addr_app_rsv = SYSBOOT_APP_BASE_OUTER;
	if( app_location == APP_LOCATION_INNER ){
		addr_app_rsv = SYSBOOT_APP_BASE_INNER;
	}
	uint32_t addr = addr_app_rsv + APP_RSV_OFFSET+p_rom_gb->app_offset;
	return addr;
}

static uint32_t udsf_udk_addr_get_signature(void){

	uint32_t addr = SYSBOOT_APP_BASE_OUTER;
	addr += p_rom_gb->app_offset;
	addr += SIGNATURE_RSV_OFFSET;

	return addr;
}

static uint32_t udsf_udk_addr_get_activate(void){
	uint32_t addr = SYSBOOT_ACTIVATE_OUTER;
	return addr;
}

static uint32_t udsf_udk_addr_get_key(void){
	uint32_t addr = SYSBOOT_KEY_OUTER;
	return addr;
}

static uint32_t udsf_udk_addr_get_opt_data(uint8_t app_location){

	uint32_t app_size = APP_HEAD_SIZE;
	uint32_t opt_data_addr = 0;

	UDF_INFO * udf_info = &paramFunc->udf01_info;
	for( int i=0;i<UDF_MAX_NUM;i++ ){
		if( paramFunc->udfEn & (1<<i) ){
			app_size += udf_info[i].len+4;
		}
	}

	if( app_location == APP_LOCATION_INNER ){
		opt_data_addr = app_size + SYSBOOT_APP_BASE_INNER + p_rom_gb->app_offset;
	}else{
		opt_data_addr = app_size + SYSBOOT_APP_BASE_OUTER + p_rom_gb->app_offset;
	}

	return opt_data_addr;
}

#endif
